/**
 * 地区ID枚举
 */
export enum RegionId {
    ALL = 0,
    MAINLAND = 1,
    HONGKONG_TAIWAN = 2,
    WESTERN = 3,
    KOREA = 4,
    JAPAN = 5,
    OTHER = 6,
}

/**
 * 语言ID枚举
 */
export enum LanguageId {
    ALL = 0,
    CHINESE = 1,
    WESTERN = 2,
    KOREAN_JAPANESE = 3,
    OTHER = 4,
}

/**
 * 地区ID到名称的映射
 */
export const REGION_NAME_MAP: Record<RegionId, string> = {
    [RegionId.ALL]: "全部",
    [RegionId.MAINLAND]: "内地",
    [RegionId.HONGKONG_TAIWAN]: "港台",
    [RegionId.WESTERN]: "欧美",
    [RegionId.KOREA]: "韩国",
    [RegionId.JAPAN]: "日本",
    [RegionId.OTHER]: "其他",
}

/**
 * 语言ID到名称的映射
 */
export const LANGUAGE_NAME_MAP: Record<LanguageId, string> = {
    [LanguageId.ALL]: "全部",
    [LanguageId.CHINESE]: "华语",
    [LanguageId.WESTERN]: "欧美",
    [LanguageId.KOREAN_JAPANESE]: "日韩",
    [LanguageId.OTHER]: "其他",
}

/**
 * 地区名称到ID的映射
 */
export const REGION_ID_MAP: Record<string, RegionId> = Object.entries(REGION_NAME_MAP).reduce(
    (acc, [id, name]) => {
        acc[name] = Number(id) as RegionId
        return acc
    },
    {} as Record<string, RegionId>,
)

/**
 * 语言名称到ID的映射
 */
export const LANGUAGE_ID_MAP: Record<string, LanguageId> = Object.entries(LANGUAGE_NAME_MAP).reduce(
    (acc, [id, name]) => {
        acc[name] = Number(id) as LanguageId
        return acc
    },
    {} as Record<string, LanguageId>,
)

/**
 * 所有地区ID数组
 */
export const ALL_REGION_IDS = Object.values(RegionId).filter((id) => typeof id === "number") as RegionId[]

/**
 * 所有语言ID数组
 */
export const ALL_LANGUAGE_IDS = Object.values(LanguageId).filter((id) => typeof id === "number") as LanguageId[]

/**
 * 根据语言ID获取可用的地区ID
 */
export function getRegionIdsByLanguageId(languageId: LanguageId): RegionId[] {
    switch (languageId) {
        case LanguageId.CHINESE:
            return [RegionId.ALL, RegionId.MAINLAND, RegionId.HONGKONG_TAIWAN]
        case LanguageId.WESTERN:
            return [RegionId.ALL, RegionId.WESTERN]
        case LanguageId.KOREAN_JAPANESE:
            return [RegionId.ALL, RegionId.KOREA, RegionId.JAPAN]
        case LanguageId.OTHER:
            return [RegionId.ALL, RegionId.OTHER]
        default:
            return ALL_REGION_IDS
    }
}

/**
 * 获取地区名称
 */
export function getRegionName(regionId: RegionId): string {
    return REGION_NAME_MAP[regionId] || REGION_NAME_MAP[RegionId.ALL]
}

/**
 * 获取语言名称
 */
export function getLanguageName(languageId: LanguageId): string {
    return LANGUAGE_NAME_MAP[languageId] || LANGUAGE_NAME_MAP[LanguageId.ALL]
}

/**
 * 获取地区ID
 */
export function getRegionId(regionName: string): RegionId {
    return REGION_ID_MAP[regionName] || RegionId.ALL
}

/**
 * 获取语言ID
 */
export function getLanguageId(languageName: string): LanguageId {
    return LANGUAGE_ID_MAP[languageName] || LanguageId.ALL
}

